﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAnalyticsTools.Models
{
    /// <summary>
    /// 高度相关特征对
    /// </summary>
    public class HighlyCorrelatedFeaturePair
    {
        /// <summary>
        /// 第一个特征的索引
        /// </summary>
        public int FeatureIndex1 { get; set; }

        /// <summary>
        /// 第二个特征的索引
        /// </summary>
        public int FeatureIndex2 { get; set; }

        /// <summary>
        /// 相关系数值，范围[-1, 1]
        /// </summary>
        public float Correlation { get; set; }

        /// <summary>
        /// 相关系数的绝对值，用于排序
        /// </summary>
        public float AbsoluteCorrelation => Math.Abs(Correlation);

        /// <summary>
        /// 相关性强度描述
        /// </summary>
        public string StrengthDescription
        {
            get
            {
                var absCorr = AbsoluteCorrelation;
                if (absCorr >= 0.9) return "极强相关";
                if (absCorr >= 0.7) return "强相关";
                if (absCorr >= 0.5) return "中等相关";
                if (absCorr >= 0.3) return "弱相关";
                return "极弱相关";
            }
        }

        public HighlyCorrelatedFeaturePair(int featureIndex1, int featureIndex2, float correlation)
        {
            FeatureIndex1 = featureIndex1;
            FeatureIndex2 = featureIndex2;
            Correlation = correlation;
        }

        public override string ToString()
        {
            return $"特征{FeatureIndex1}与特征{FeatureIndex2}: {Correlation:F3} ({StrengthDescription})";
        }
    }
}
